package com.onec.service.customer.entity.agent;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.onec.service.api.content.AesEntityContent;
import com.onec.service.api.enums.ProductEnum;
import com.onec.service.api.enums.StatusEnum;
import lombok.Data;
import org.hibernate.annotations.ColumnTransformer;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 代理商
 * 渠道信息。
 *
 * @author ONEC
 */
@Data
@Entity
@Table(name = "t_agent_account")
public class AgentAccount implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true)
    private Long id;

    @Column(name = "version", length = 8)
    private Integer version;

    @Column(name = "agent_id", length = 16)
    private Long agentId;
    /**
     * 通道编号
     */
    @Column(name = "total_amount", length = 8, scale = 2)
    private BigDecimal totalAmount;
    /**
     * 通道名称
     */
    @Column(name = "freeze_amount", length = 8, scale = 2)
    private BigDecimal freezeAmount;

    /**
     * 联系人
     */
    @Column(name = "use_amount", length = 8, scale = 2)
    private BigDecimal useAmount;


    @Column(name = "product", length = 8)
    @Enumerated(EnumType.STRING)
    private ProductEnum product;

    @Column(name = "contacts", length = 32)
    private String contacts;

    /**
     * 机构编号
     */
    @Column(name = "phone", length = 128)
    @ColumnTransformer(
            read = AesEntityContent.AES_DECRYPT_PHONE,
            write = AesEntityContent.AES_ENCRYPT_PHONE
    )
    private String phone;
    /**
     * 创建时间
     */
    @Column(name = "create_time", length = 0, updatable = false)
    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date createTime;
    /**
     * 变更
     */
    @Column(name = "update_time", length = 0)
    @Temporal(TemporalType.TIMESTAMP)
    @LastModifiedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date updateTime;
    /**
     * 创建者
     */
    @Column(name = "creator", length = 32)
    private String creator;
    /**
     * 产品备注
     */
    @Column(name = "remarks", length = 64)
    private String remarks;
    /**
     * 通道状态
     */
    @Column(name = "status", length = 12)
    @Enumerated(EnumType.STRING)
    private StatusEnum status;


    public AgentAccount() {
    }


    public AgentAccount(Integer version, BigDecimal totalAmount, BigDecimal freezeAmount, BigDecimal useAmount,
                        ProductEnum product, String contacts, String phone, Date createTime,
                        Date updateTime, String creator, String remarks, StatusEnum status, Long agentId) {
        this.version = version;
        this.totalAmount = totalAmount;
        this.freezeAmount = freezeAmount;
        this.useAmount = useAmount;
        this.product = product;
        this.contacts = contacts;
        this.phone = phone;
        this.createTime = createTime;
        this.updateTime = updateTime;
        this.creator = creator;
        this.remarks = remarks;
        this.status = status;
        this.agentId = agentId;
    }


}
